package com.lbkj.ops;

import com.lbkj.ops.common.util.ServletUtils;
import com.lbkj.ops.common.util.SessionUtils;
import com.lbkj.ops.model.OpsUser;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@SpringBootApplication
public class OpsApplication {

    public static void main(String[] args) {
        SpringApplication.run(OpsApplication.class, args);
    }

    @RequestMapping
    public String index() {
        OpsUser loginUser = SessionUtils.getLoginUser();
        if(loginUser == null) {
            return "redirect:/login";
        }
        ServletUtils.getRequest().setAttribute("username", loginUser.getName());
        return "index";
    }

    @RequestMapping(path = "/login", method = RequestMethod.GET)
    public String login() {
        return "login";
    }

    @RequestMapping("/ui/{page}")
    public String index(@PathVariable String page) {
        ServletUtils.getRequest().setAttribute("_RID", "R-" + page);
        return page;
    }
}
